// WF1996 - Philadelphia, UVa247 - Calling Circles
// 陈锋
#include <bits/stdc++.h>
using namespace std;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
vector<string> names;
map<string, int> indice;
int getID(const string& s) {  // 获取结点ID
  if (!indice.count(s)) indice[s] = names.size(), names.push_back(s);
  return indice[s];
}
int main() {
  string A, B;
  for (int t = 1, N, M; cin >> N >> M && N; t++) {
    if (t > 1) cout << endl;
    vector<bool> VIS(N + 1);
    vector<vector<int>> G(N + 1, vector<int>(N + 1));
    _for(i, 0, M) cin >> A >> B, G[getID(A)][getID(B)] = 1;
    _for(k, 0, N) _for(i, 0, N) _for(j, 0, N) G[i][j] |= G[i][k] && G[k][j];
    cout << "Calling circles for data set " << t << ":" << endl;
    _for(u, 0, N) {
      if (VIS[u]) continue;
      cout << names[u], VIS[u] = 1;
      _for(v, 0, N) if (G[u][v] && G[v][u] && !VIS[v]) VIS[v] = 1,
                                                       cout << ", " << names[v];
      cout << endl;
    }
    names.clear(), indice.clear();
  }
  return 0;
}
/*
算法分析请参考: 《入门经典-第2版》例题11-4
*/
// Accepted 10ms 1188 C++ 5.3.0 2020-12-1416:34:58 25846331
